// import { codes } from '@renderer/data'
// import useCode from '@renderer/hooks/useCode'
import { useStore } from '@renderer/store/useStore'
import { ChangeEvent } from 'react'
export default () => {
  // const { setData } = useCode()
  const setData = useStore((state) => state.setData)
  // const [search, setSearch] = useState('')
  const search = useStore((state) => state.search)
  const setSearch = useStore((state) => state.setSearch)
  const handleSearch = async (e: ChangeEvent<HTMLInputElement>) => {
    const title = e.target.value
    setSearch(title)
    const data = await window.api.sql(
      `select * from contents where title like @title limit 6`,
      'findAll',
      { title: `%${title}%` },
    )
    setData(title ? (data as ContentType[]) : [])
  }
  return {
    search,
    handleSearch,
  }
}
